import datetime

########LOGGING##########
WORKING_DIR = '/data/'
LOGGING_CONF='log.conf'

####DISCOVERY CONFIGURATION###

DO_DNS = False
DO_NBSCAN = False
DO_SMBSCAN = False


SOFT_TIMEOUT = datetime.timedelta(seconds = 100)
HARD_TIMEOUT = datetime.timedelta(seconds = 200)
DISCOVERY_TIMEOUT = datetime.timedelta(seconds = 1000)


#####TASKER CONFIGURATION#################
SIM_TASKS = 0
SIM_SCANS = 1

MAX_RUNNING_TASKS = 4

SCAN_REPORT_DIR = '/data/reports/'
SCAN_REPORT_LINK = 'http://192.168.70.65/reports/'
#DB Connections
DB_DEBUG = False 
DMZWATCH_DB = 'mysql+mysqlconnector://root:123456@127.0.0.1/dmzwatch'
NETADMIN_DB = 'mysql+mysqlconnector://dmzwatch:ht7KL_2x@10.0.0.7/netadmin'
INCIDENT_DB = ''
VARCHAR_LENGTH = 2000
TEXT_LENGTH = 2**30


###OPENVAS##
MAX_OPENVAS_TASKS = 1
#openvas low level prefixes
TARGET_PREFIX = 'dmzwatch_'
TASK_PREFIX = 'dmzwatch_'

#openvas manager connection 
MANAGER_ADDRESS = '127.0.0.1'
MANAGER_PORT = '9390'
MANAGER_USER = 'admin'
MANAGER_PASSWORD = '123456'


#Jabber connection
#aeaestrea
ASTRAEA_JID = 'astraea@192.168.70.199/astraea'
ASTRAEA_PASS = 'LB--ic_vvZ8m_4aF'
RESPONSIBLE_JID = 'praktika1@192.168.70.199'


##################ENUMS#################
def enum(*sequential, **named):
    
    enums = dict(zip(sequential, range(len(sequential))), **named)
    reverse = dict((value, key) for key, value in enums.items())
    enums['reverse_mapping'] = reverse
    return type('Enum', (), enums)
    
    
HostStatus = enum(
                active      = 'active', 
                inactive    = 'inactive', 
                vanished    = 'vanished', 
                returned    = 'returned'
                )
                

Network = enum(
                    dmz         = 'dmz',
                    vip         = 'home-vip',
                    roffice     = 'roffice',
                    pix         = 'pix',
                    unknown     = 'unknown'
                    )    
                                        
def task_by_network():
    return dict({
                Network.dmz         : TaskType.typical,
                Network.roffice     : TaskType.typical,
                Network.pix         : TaskType.typical,
                Network.unknown     : TaskType.safest
                })

Cause = enum(
                    new         = 'new host',
                    periodic    = 'periodic discovery',
                    returned    = 'returned host',
                    network     = 'new network',
                    external    = 'external command'
                )
def incident_by_cause():
    return     dict({
    
                    Cause.new           : [IncidentType.dmzwatch_new_host,              Severity.high],
                    Cause.periodic      : [IncidentType.dmzwatch_periodic_discovery,    Severity.medium],
                    Cause.returned      : [IncidentType.dmzwatch_returned_host,         Severity.medium],
                    Cause.network       : [IncidentType.dmzwatch_sudden_network,        Severity.high],
                    Cause.external      : [IncidentType.dmzwatch_forced_discovery,      Severity.high]
                })
                
ExecStatus = enum(
                    new         = 'new',
                    running     = 'running',
                    complete    = 'complete',
                    error       = 'error'
                    )

                 
IncidentType = enum(
                    dmzwatch_new_host               = 'dmzwatch_new_host',                            
                    dmzwatch_vanished_host          = 'dmzwatch_vanished_host',                  
                    dmzwatch_returned_host          = 'dmzwatch_returned_host',                  
                    dmzwatch_periodic_discovery     = 'dmzwatch_periodic_discovery',        
                    dmzwatch_sudden_network         = 'dmzwatch_sudden_network',                
                    dmzwatch_forced_discovery       = 'dmzwatch_forced_discovery',             
                    
                    dmzwatch_service                = 'dmzwatch_service',                              
                    dmzwatch_vuln                   = 'dmzwatch_vuln',                                    

                    dmzwatch_unknown                = 'dmzwatch_unknown',                              
                    dmzwatch_internal_error         = 'dmzwatch_internal_error'            
                    )

IncidentDestination = enum(
                    db          = 'database',
                    astraea     = 'astraea_xmpp',
                    responsible = 'responsible_xmpp',
                    snmp        = 'snmp_trap',
                    
                    )
def destination_by_type():
    return dict(
                    {
                        'default'                               : [IncidentDestination.db,      IncidentDestination.responsible],
                        'high_severity'                         : [IncidentDestination.astraea, IncidentDestination.snmp, IncidentDestination.db, IncidentDestination.responsible],
                        
                        IncidentType.dmzwatch_internal_error    : [IncidentDestination.responsible],
                        IncidentType.dmzwatch_unknown           : [IncidentDestination.responsible]
                        
                    }
                )
TaskType = enum (
                safest = 'safest',
                basic = 'basic',
                typical = 'typical',
                custom = 'custom',
                openvas_only = 'openvas_only'
                
                )             
                    
def scans_by_task():
    return dict({
                    TaskType.safest         : ScanType.nmap_safe,
                    TaskType.basic          : ScanType.nmap_normal,
                    TaskType.typical        : ScanType.nmap_normal + ',' + ScanType.openvas_normal,
                    TaskType.openvas_only   : ScanType.openvas_normal
                })
                    
ScanType = enum(

                 nmap_full          = 'nmap_full',      
                 nmap_normal        = 'nmap',          
                 nmap_safe          = 'nmap_safe',      
                 openvas_normal     = 'openvas_normal',
                 divine_power       = 'chuck_norris'
                 
                 )
def scansbytype():
    return dict({
                    ScanType.nmap_full       : ['nmap', {'args' : '-sS -sU  -A -T4 -PE -PP --script \"default or (discovery and safe)\"'}],
                    ScanType.nmap_normal     : ['nmap', {'args' : '-sS -sU  -T5 -PE -PP --script \"default or (discovery and safe)\" '}],
                    ScanType.nmap_safe       : ['nmap', {'args' : '-sS -sU  -T4 -PE -PP'}],
                    ScanType.openvas_normal  : ['openvas', { 
                                                    'default_config' : 'Full and fast', 
                                                    'default_portlist' : 'Nmap 5.51 top 2000 TCP and top 100 UDP'
                                                    }]
                })
                
                
                
Severity = enum(
                    info    = '0',
                    low     = '1',
                    medium  = '2',
                    high    = '3'
                    )    
